1. Field of the Invention
The present invention relates to a system and method for creating composite classes for objects having virtual functions, wherein the composite classes enable avoidance of user mode/kernel mode transitions in the operating system.
2. Description of the Related Art
A common need in many software programs, such as device driver programs, is the ability to use an object in both user and kernel modes. However, an object which contains virtual functions, and hence a virtual function table pointer, cannot be shared directly between user and kernel mode. Sharing is not possible for objects which include virtual functions for the following reason. When a virtual function of the object is called, the address of the function is retrieved from the object's virtual function table. The object itself contains a pointer to its virtual function table, referred to as vfptr, and this pointer is used to retrieve the address of the virtual function that is called. If an object is created in the kernel, the object's virtual function table pointer (vfptr) will be a kernel pointer, which is inaccessible in user mode under some operating systems. If an object is created in user mode, the object's virtual function table pointer (vfptr) will be a user pointer which may be invalid in the kernel if the user mode process is not in context. Therefore due to these virtual function table pointers, objects that contain virtual functions cannot be directly shared between user and kernel modes.
One way to work around this problem is to implement a "proxy design pattern". The proxy design pattern creates a proxy object in user mode that forwards requests to the real object in kernel mode. However, this forwarding of requests involves a user to kernel mode transition. A user to kernel mode transition is an expensive operation in terms of time, i.e., CPU cycles. With the use of proxies, whenever a request is made of a proxy object, this user to kernel mode transition occurs. This time penalty can be unacceptable for operations that require fast execution, such as memory allocation and manipulation.
Quantitative Benchmarks of User to Kernel Mode Transition Costs
Below are benchmarks that were compiled to compare the time duration that a function call takes to complete when the caller and the callee are in the same executable versus when the callee is in the kernel and a user to kernel mode transition is required. The experiments were done using two different computers: a Dell Dimension XPS p166c and a 486 machine whose CPU has been upgraded to Evergreen 586 100 MHz. It is noted that the benchmark results should not be treated as absolute numbers, because the numbers depend on the environment (CPU, compiler, machine, memory state, register values, etc.) in which the experiment was conducted.
______________________________________ Dell P166 Windows NT: local 72.6 kernel 34600 Windows 95: local 85.1 kernel 6840 Evergreen 586 100 MHz Windows NT: local 446 kernel 138000 Windows 95: local 473 kernel 26100 ______________________________________
From the above benchmark figures it is readily apparent that function calls involving user to kernel mode transitions are much more expensive than function calls within the same executable (especially under Windows NT). Thus the use of proxies to solve the object sharing problem is not sufficient in some circumstances.
Therefore, an improved system and method is desired for enabling use of objects which comprise virtual functions in both user and kernel modes, wherein this usage does not require, or requires a reduced number of, user mode/kernel mode transitions.